﻿using CleanArchitecture.Infrastructure.Entities.Settings;
using CleanArchitecture.Infrastructure.Models.AdminUsers;
using FluentValidation;

namespace CleanArchitecture.Web.Validators.AdminUsers
{
    public partial class AccountValidator : BaseModelValidator<AdminUserModel>
    {
        public AccountValidator(AdminUserSettings adminuserSettings)
        {
            RuleFor(x => x.UserLoginName).IsLoginUsername(adminuserSettings)
                .WithMessage(ValidatorRuleString.LoginNameNotValid);
            RuleFor(x => x.Email).EmailAddress().WithMessage(ValidatorRuleString.EmailNotValid);

            int passwordminLen = adminuserSettings.PasswordMinLength ?? 6;
            RuleFor(x => x.NewPassword).IsLoginPasswordCorrect(passwordminLen).When(x =>
            {
                return string.IsNullOrEmpty(x.NewPassword) ? false : true;
            });
        }
    }
}